﻿using System.Collections.Generic;
using System.Linq;
using Freedom.Repository.Interface;
using Freedom.Repository.Models;

namespace Freedom.Repository.Repository
{
    public class ProductRepository : IProductRepository
    {
        private readonly FreedomContext _context;
        public ProductRepository(FreedomContext context)
        {
            _context = context;
        }

        #region Implementation of IProductRepository

        public IEnumerable<Product> GetAllProducts()
        {
                return (from p in _context.Products
                        select p).ToArray();
        }

        public int GetTotalCount()
        {
            var products = from p in _context.Products
                           select p;

            var count = products.Count();
            return count;
        }


        public IEnumerable<Product> GetPageProducts(int pagenum, int pagesize, string sortDataField = null, string sortOrder = "")
        {
            var products = from p in _context.Products
                           select p;

            return products.OrderBy(p => p.Id).Skip(pagenum * pagesize).Take(pagesize).ToList();
        }
        #endregion
    }
}
